package com.spring.mvc.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0.0
 * @Date: 2022/7/3 14:11
 * @Author ZhuYouBin
 * @Description
 */
@RestController
@RequestMapping("/exception")
public class ExceptionController {

    @RequestMapping(value = "/demo", produces = {"text/html;charset=utf-8"})
    public String demo() {
        String msg = "操作成功";
        try {
            // 模拟处理异常
            int i = 10 / 0;
        } catch (Exception e) {
            e.printStackTrace();
            msg = "未知异常，请联系管理员！";
        }
        return msg;
    }

    @RequestMapping(value = "/demo02", produces = {"text/html;charset=utf-8"})
    public String demo02() {
        // 使用了全局异常处理，控制层就可以不用try...catch异常捕获
        // TODO 模拟处理异常
        int i = 10 / 0;
        return "操作成功";
    }

}
